/*
 * $Id$
 *
 * Copyright ( c ) 2014 XuNuo Corporation. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of XuNuo
 * Corporation ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with XuNuo Corporation or a XuNuo
 * authorized reseller (the "License Agreement"). XuNuo may make changes to the
 * Confidential Information from time to time. Such Confidential Information may
 * contain errors.
 *
 * EXCEPT AS EXPLICITLY SET FORTH IN THE LICENSE AGREEMENT, XuNuo DISCLAIMS ALL
 * WARRANTIES, COVENANTS, REPRESENTATIONS, INDEMNITIES, AND GUARANTEES WITH
 * RESPECT TO SOFTWARE AND DOCUMENTATION, WHETHER EXPRESS OR IMPLIED, WRITTEN OR
 * ORAL, STATUTORY OR OTHERWISE INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A
 * PARTICULAR PURPOSE. XuNuo DOES NOT WARRANT THAT END USER'S USE OF THE
 * SOFTWARE WILL BE UNINTERRUPTED, ERROR FREE OR SECURE.
 *
 * XuNuo SHALL NOT BE LIABLE TO END USER, OR ANY OTHER PERSON, CORPORATION OR
 * ENTITY FOR INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL
 * DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR USE, WHETHER IN AN
 * ACTION IN CONTRACT, TORT OR OTHERWISE, EVEN IF XuNuo HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES. XuNuo' TOTAL LIABILITY TO END USER SHALL NOT
 * EXCEED THE AMOUNTS PAID FOR THE XuNuo SOFTWARE BY END USER DURING THE PRIOR
 * TWELVE (12) MONTHS FROM THE DATE IN WHICH THE CLAIM AROSE.  BECAUSE SOME
 * STATES OR JURISDICTIONS DO NOT ALLOW LIMITATION OR EXCLUSION OF CONSEQUENTIAL
 * OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO END USER.
 *
 * Copyright version 2.0
 */
package com.th.supcom.pds.phamapply.client.widget.phamapplydetail;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.th.supcom.pds.common.client.widget.PdsGrid;
import com.th.supcom.pds.phamapply.client.model.InpPhamApplyDetailModel;

/**
 * 退药药品Grid
 * 
 * @author 杨冲
 */
public class PhamApplyOffsetGrid extends PdsGrid <InpPhamApplyDetailModel>
{
    public PhamApplyOffsetGrid ()
    {
        setHeaderVisible (true);
        setHeading ("需要退药药品");
    }

    @Override
    public ColumnModel createColumnModel ()
    {
        List <ColumnConfig> configs = new ArrayList <ColumnConfig> ();
        ColumnConfig column = null;
        column = new ColumnConfig ("phamName", "药品名称", 150);
        configs.add (column);
        column = new ColumnConfig ("phamSpec", "规格", 150);
        configs.add (column);
        column = new ColumnConfig ("offsetSum", "包装数量", 80);
        column.setAlignment (HorizontalAlignment.RIGHT);
        column.setRenderer (getOffsetAmountRenderer ());
        configs.add (column);
        return new ColumnModel (configs);
    }

    /**
     * 获取摆药数量
     * 
     * @return
     */
    private GridCellRenderer <InpPhamApplyDetailModel> getOffsetAmountRenderer ()
    {
        return new GridCellRenderer <InpPhamApplyDetailModel> ()
        {

            @Override
            public Object render (InpPhamApplyDetailModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore <InpPhamApplyDetailModel> store,
                                  Grid <InpPhamApplyDetailModel> grid)
            {
                return model.getOffsetSum ().intValue () + model.getApplyUnitName ();
            }
        };
    }

}
